//
//  KYAppInfoView.m
//  KYKJPackDemo
//
//  Created by Jordan zhou on 2017/9/25.
//  Copyright © 2017年 ???. All rights reserved.
//

#import "KYAppInfoView.h"

@interface KYAppInfoView()
/**
 *  app图标
 */
@property (nonatomic, weak) UIImageView *appImg;

/**
 *  app名称
 */
@property (nonatomic, weak) UILabel *appLabel;

/**
 *  版本描述
 */
@property (nonatomic, weak) UILabel *infoLabel;
@end

@implementation KYAppInfoView

+ (instancetype)customInfoView {
    return [[self alloc] init];
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setUpSubViews];
    }
    
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder:decoder]) {
        [self setUpSubViews];
    }
    
    return self;
}

- (void)setUpSubViews
{
    UIImageView *appImg = [[UIImageView alloc] init];
    appImg.image = [UIImage imageWithName:@"me"];
    appImg.layer.cornerRadius = 15;
    appImg.clipsToBounds = YES;
    [self addSubview:appImg];
    self.appImg = appImg;
    
    UILabel *appLabel = [[UILabel alloc] init];
    appLabel.text = NSLocalizedString(@"朵啦摄影", nil);
    appLabel.textAlignment = NSTextAlignmentCenter;
    appLabel.font = [UIFont boldSystemFontOfSize:17];
    [self addSubview:appLabel];
    self.appLabel = appLabel;
    
    UILabel *infoLabel = [[UILabel alloc] init];
    infoLabel.text = NSLocalizedString(@"v1.1.0", nil);
    infoLabel.textAlignment = NSTextAlignmentCenter;
    infoLabel.font = [UIFont systemFontOfSize:13];
    infoLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:infoLabel];
    self.infoLabel = infoLabel;
}

/**
 *  拿到真实尺寸设置frame
 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat appImgX = self.frame.size.width * 0.5;
    CGFloat appImgH = 100;
    CGFloat appImgY = 50 + appImgH * 0.5;
    CGFloat appImgW = appImgH;
    self.appImg.center = CGPointMake(appImgX, appImgY);
    self.appImg.bounds = CGRectMake(0, 0, appImgW, appImgH);
    
    CGFloat appLabelX = 0;
    CGFloat appLabelY = CGRectGetMaxY(self.appImg.frame);
    CGFloat appLabelW = self.frame.size.width;
    CGFloat appLabelH = 40;
    self.appLabel.frame = CGRectMake(appLabelX, appLabelY, appLabelW, appLabelH);
    
    CGFloat infoLabelX = 0;
    CGFloat infoLabelY = CGRectGetMaxY(self.appLabel.frame);
    CGFloat infoLabelW = appLabelW;
    CGFloat infoLabelH = 20;
    self.infoLabel.frame = CGRectMake(infoLabelX, infoLabelY, infoLabelW, infoLabelH);
}


@end
